package clustering;



import graphNew.MainGraph;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import main.Translating;

import org.jgrapht.graph.DefaultWeightedEdge;

import components.Operator;

//this class represents the Voltage Cluster algorithm
public class VoltageCluster implements ClusteringIfc {
	
	private int num_candidates;
	private MainGraph graph;
	private Set<VerticesSet> clusterSet;	

	public VoltageCluster(int _num_candidates) {
		this.num_candidates = _num_candidates;
		this.clusterSet = new HashSet<VerticesSet> ();
	}

	@Override
	//creates jungGraph from a given graph,
	//creates cluster set according to VoltageCluster algorithm, and returns set of vertex sets 
	//out of that cluster result
	public Set<VerticesSet> cluster(MainGraph graph, int num_clusters) {
		this.graph = graph;
		edu.uci.ics.jung.graph.Graph<Operator, DefaultWeightedEdge> jungGraph = Translating.ourGraphToJungGraph(graph);
		
		edu.uci.ics.jung.algorithms.cluster.VoltageClusterer<Operator, DefaultWeightedEdge> vc =
			new edu.uci.ics.jung.algorithms.cluster.VoltageClusterer<Operator, DefaultWeightedEdge>(jungGraph, this.num_candidates);
		
		Collection<Set<Operator>> clusteredSet = vc.cluster(num_clusters);
		
		for (Set<Operator> vertexSet : clusteredSet){
			VerticesSet vSet = new VerticesSet(vertexSet);
			this.clusterSet.add(vSet);
		}
		
		return clusterSet;
	}

	public int getNum_candidates() {
		return num_candidates;
	}
	
	
		

}
